//
//  GYEmoticonPageView.swift
//  Weibo
//
//  Created by vane on 16/8/18.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
private let GYEmoticonPageViewCellId = "GYEmoticonPageViewCellId"
class GYEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
            setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        backgroundColor = RandomColor()
        
        dataSource = self
        
        registerClass(GYEmoticonPageViewCell.self, forCellWithReuseIdentifier: GYEmoticonPageViewCellId)
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = self.frame.size
        
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = .Horizontal

    }

}
extension GYEmoticonPageView:UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        
        return GYEmoticonTools.shardTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return GYEmoticonTools.shardTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(GYEmoticonPageViewCellId, forIndexPath: indexPath) as! GYEmoticonPageViewCell
        
//        cell.indexPath = indexPath
        
        cell.emoticons = GYEmoticonTools.shardTools.allEmoticons[indexPath.section][indexPath.item]
        
        
        return cell
    }
    
    
    
    
}